/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.model;

import java.text.NumberFormat;
import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

/**
 * 
 */
public class HeteroParam {
	private static ArrayList<HeteroParam> paramList;

	static {
		paramList = new ArrayList<HeteroParam>();
		paramList.add(Player.PT_DEFAULT, new HeteroParam());
		paramList.add(Player.PT_HETRO_A, new HeteroParam());
		paramList.add(Player.PT_HETRO_B, new HeteroParam());
		paramList.add(Player.PT_HETRO_C, new HeteroParam());
		paramList.add(Player.PT_HETRO_D, new HeteroParam());
		paramList.add(Player.PT_HETRO_E, new HeteroParam());
		paramList.add(Player.PT_HETRO_F, new HeteroParam());
	}

	public static void put(int type, HeteroParam hp) {
		paramList.set(type, hp);
	}

	public static HeteroParam get(int type) {
		return paramList.get(type);
	}

	public final static int ID = 0;

	public final static int PLAYER_SPEED_MAX = 1;

	public final static int STAMINA_INC_MAX = 2;

	public final static int PLAYER_DECAY = 3;

	public final static int INERTIA_MOMENT = 4;

	public final static int DASH_POWER_RATE = 5;

	public final static int PLAYER_SIZE = 6;

	public final static int KICKABLE_MARGIN = 7;

	public final static int KICK_RAND = 8;

	public final static int EXTRA_STAMINA = 9;

	public final static int EFFORT_MAX = 10;

	public final static int EFFORT_MIN = 11;

	private final static String colName[] = { "id", "player speed max",
			"stamina inc max", "player decay", "inertia moment",
			"dash power rate", "player size", "kickable margin", "kick rand",
			"extra stamina", "effort max", "effort min" };

	public static TableModel getTableModel() {
		TableModel dataModel = new AbstractTableModel() {
			@Override
			public String getColumnName(int column) {
				return colName[column];
			}

			public int getColumnCount() {
				return 12;
			}

			public int getRowCount() {
				return paramList.size();
			}

			public Object getValueAt(int row, int col) {
				if (col == ID)
					return new Integer(row);
				return HeteroParam.get(row).getValueAt(col);
			}
		};
		return dataModel;
	}

	public float player_speed_max;

	public float stamina_inc_max;

	public float player_decay;

	public float inertia_moment;

	public float dash_power_rate;

	public float player_size;

	public float kickable_margin;

	public float kick_rand;

	public float extra_stamina;

	public float effort_max;

	public float effort_min;

	public HeteroParam() {
		this.player_speed_max = Param.PLAYER_SPEED_MAX;
		this.stamina_inc_max = Param.STAMINA_INC_MAX;
		this.player_decay = Param.PLAYER_DECAY;
		this.inertia_moment = Param.INERTIA_MOMENT;
		this.dash_power_rate = Param.DASH_POWER_RATE;
		this.player_size = Param.PLAYER_SIZE;
		this.kickable_margin = Param.KICKABLE_MARGIN;
		this.kick_rand = 0.0f;
		this.extra_stamina = 0.0f;
		this.effort_max = Param.EFFORT_MAX;
		this.effort_min = Param.EFFORT_MIN;
	}

	public HeteroParam(HeteroParam hp) {
		this.player_speed_max = hp.player_speed_max;
		this.stamina_inc_max = hp.stamina_inc_max;
		this.player_decay = hp.player_decay;
		this.inertia_moment = hp.inertia_moment;
		this.dash_power_rate = hp.dash_power_rate;
		this.player_size = hp.player_size;
		this.kickable_margin = hp.kickable_margin;
		this.kick_rand = hp.kick_rand;
		this.extra_stamina = hp.extra_stamina;
		this.effort_max = hp.effort_max;
		this.effort_min = hp.effort_min;
	}

	public HeteroParam(float player_speed_max, float stamina_inc_max,
			float player_decay, float inertia_moment, float dash_power_rate,
			float player_size, float kickable_margin, float kick_rand,
			float extra_stamina, float effort_max, float effort_min) {
		this.player_speed_max = player_speed_max;
		this.stamina_inc_max = stamina_inc_max;
		this.player_decay = player_decay;
		this.inertia_moment = inertia_moment;
		this.dash_power_rate = dash_power_rate;
		this.player_size = player_size;
		this.kickable_margin = kickable_margin;
		this.kick_rand = kick_rand;
		this.extra_stamina = extra_stamina;
		this.effort_max = effort_max;
		this.effort_min = effort_min;
	}

	public HeteroParam(float[] params) {
		this.player_speed_max = params[0];
		this.stamina_inc_max = params[1];
		this.player_decay = params[2];
		this.inertia_moment = params[3];
		this.dash_power_rate = params[4];
		this.player_size = params[5];
		this.kickable_margin = params[6];
		this.kick_rand = params[7];
		this.extra_stamina = params[8];
		this.effort_max = params[9];
		this.effort_min = params[10];
	}

	@Override
	public String toString() {
		NumberFormat form = NumberFormat.getInstance();
		form.setMaximumFractionDigits(3);
		form.setMinimumFractionDigits(3);
		return (form.format(this.player_speed_max) + " "
				+ form.format(this.stamina_inc_max) + " "
				+ form.format(this.player_decay) + " "
				+ form.format(this.inertia_moment) + " "
				+ form.format(this.dash_power_rate) + " "
				+ form.format(this.player_size) + " "
				+ form.format(this.kickable_margin) + " "
				+ form.format(this.kick_rand) + " "
				+ form.format(this.extra_stamina) + " "
				+ form.format(this.effort_max) + " " + form
				.format(this.effort_min));
	}

	public Object getValueAt(int col) {
		NumberFormat form = NumberFormat.getInstance();
		form.setMaximumFractionDigits(3);
		form.setMinimumFractionDigits(3);
		switch (col) {
		case PLAYER_SPEED_MAX:
			return form.format(this.player_speed_max);
		case STAMINA_INC_MAX:
			return form.format(this.stamina_inc_max);
		case PLAYER_DECAY:
			return form.format(this.player_decay);
		case INERTIA_MOMENT:
			return form.format(this.inertia_moment);
		case DASH_POWER_RATE:
			return form.format(this.dash_power_rate);
		case PLAYER_SIZE:
			return form.format(this.player_size);
		case KICKABLE_MARGIN:
			return form.format(this.kickable_margin);
		case KICK_RAND:
			return form.format(this.kick_rand);
		case EXTRA_STAMINA:
			return form.format(this.extra_stamina);
		case EFFORT_MAX:
			return form.format(this.effort_max);
		case EFFORT_MIN:
			return form.format(this.effort_min);
		}
		return " ";
	}
}
